/* eslint-disable import/no-anonymous-default-export */
import {add, del, list, status, upd,upload} from '../services/bannerApi';
import {imgs} from "../services/cateApi";

export default {
    state: {
        data: [],
        img:''
    },
    effects: {
        async list(params) {
            const response = await list(params)
            if (response.code === 200) {
                this.saveData({
                    data: response.data,
                    img:''

                })
            }
            return response.data
        },
        async add(params) {
            await add(params)
        },
        async del(params) {
            await del(params)
        },
        async status(params) {
            await status(params)
        },
        async upd(params) {
            await upd(params)
        },
        async upload(params) {
            const response = await upload(params)
            if (response.code === 200) {

                this.saveImg({
                    img: response.data
                })

            }
            return response
        },
    },
    reducers: {
        saveData(state, paylode) {
            return {
                ...state,
                ...paylode,

            }
        },
        saveImg(state, paylode) {
            return {
                ...state,
                ...paylode
            }
        },
        clear(state, payload) {
            return {
                ...state,
                img: '',
            }
        },
    }
}